﻿using System.ComponentModel;
using System.Globalization;
using System.Windows.Forms;
using System.Collections.Generic;

using Elegant.Ui;

namespace iPdf
{
    class FontSizeComboBox : TataComboBox
    {
        public FontSizeComboBox()
        {
            DataSource = new float[] { 8, 9, 10, 10.5f, 11, 12, 14, 16, 18, 20, 22, 24, 26, 28, 36, 48, 72 };

            Editable = true;

            TextEditor.KeyPress += TextEditor_KeyPress;
        }

        private void TextEditor_KeyPress(object sender, KeyPressEventArgs e)
        {
            NumberFormatInfo numberFormat = CultureInfo.CurrentCulture.NumberFormat;
            string numberDecimalSeparator = numberFormat.NumberDecimalSeparator;
            string numberGroupSeparator = numberFormat.NumberGroupSeparator;
            char keyCh = e.KeyChar;
            string keyCharString = keyCh.ToString();
            
            if (((!char.IsDigit(keyCh) && (!keyCharString.Equals(numberDecimalSeparator) &&
                !keyCharString.Equals(numberGroupSeparator)))) && (keyCh != '\b'))
            {
                if ((ModifierKeys & (Keys.Alt | Keys.Control)) == Keys.None)
                {
                    e.Handled = true;
                    WinApi.MessageBeep(0);
                }
            }
        }

        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public new string CommandName
        {
            get { return base.CommandName; }
            set { base.CommandName = value; }
        }

        [Browsable(false)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public new System.Windows.Forms.ComboBox.ObjectCollection Items
        {
            get { return base.Items; }
        }

        [Browsable(false)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public new object SelectedItem
        {
            get { return base.SelectedItem; }
            set { base.SelectedItem = value; }
        }

        [Browsable(false)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public new object SelectedValue
        {
            get { return base.SelectedValue; }
            set { base.SelectedValue = value; }
        }

        ///<summary>
        ///Gets or sets the data source for this combo box.
        ///</summary>
        ///
        ///<returns>
        ///An object that implements the <see cref="T:System.Collections.IList"></see> or <see cref="T:System.ComponentModel.IListSource"></see> interfaces, such as a <see cref="T:System.Data.DataSet"></see> or an <see cref="T:System.Array"></see>. The default value is null.
        ///</returns>
        ///
        ///<exception cref="T:System.ArgumentException">The assigned value does not implement the <see cref="T:System.Collections.IList"></see> or <see cref="T:System.ComponentModel.IListSource"></see> interfaces.</exception><filterpriority>1</filterpriority>
        [Browsable(false)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public new object DataSource
        {
            get { return base.DataSource; }
            set
            {
                base.DataSource = value;
            }
        }

    }
}